<template>
    <tl-sub-page :render="render" :visible.sync="visible" v-dialogDrag :title="title" :close-on-click-modal="false" class="tl-dialog" width="1100px" @open="open" @close="close">
        <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="120px" :disabled="disableEditSubmit || disableSave">
            <el-row>
                <el-col :span="24">
                    <el-divider content-position="left"><span>【项目】相关信息</span></el-divider>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="项目" prop="projectid" :required="true" :rules="rules.validateRequire">
                        <el-input v-model="model.dispprojectid" :disabled="true" class="tl-ref-selector">
                            <el-button slot="append" type="primary" icon="el-icon-search" @click="openpmProjectRefDialog" v-if="!disableEditSubmit && !disableSave"></el-button>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="项目编号">
                        <el-input v-model="model.projectcode" :disabled="true"> </el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="合同金额">
                        <el-input-number v-model="model.projectcontractmoney" controls-position="right" :step="1" :precision="2" style="width:95%" :disabled="true"></el-input-number>
                        <span>元</span>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="项目金额">
                        <el-input-number v-model="model.projectmoney" controls-position="right" :step="1" :min="0" :precision="2" style="width:95%" :disabled="true"></el-input-number>
                        <span>元</span>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="收据总金额">
                        <el-input-number v-model="model.projectreceiptmoney" controls-position="right" :step="1" :precision="2" style="width:95%" :disabled="true"></el-input-number>
                        <span>元</span>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="已收款金额">
                        <el-input-number v-model="model.projectrecbillmoney" controls-position="right" :step="1" :min="0" :precision="2" style="width:95%" :disabled="true"></el-input-number>
                        <span>元</span>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-divider content-position="left"><span>【业务类型】相关信息</span></el-divider>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="业务类型" prop="category" :rules="rules.validateRequire">
                        <el-select v-model="model.category" filterable clearable @change="currentDatas">
                            <el-option v-for="item in codeModel.categoryList" :key="item.code" :label="item.name" :value="item.code" />
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="原收据号" prop="oldreceiptcode" v-show="isCancelAndReadd" :rules="isCancelAndReadd ? rules.validateRequire : { required: false }">
                        <el-input v-model="model.oldreceiptcode" :disabled="true" class="tl-ref-selector">
                            <el-button slot="append" type="primary" icon="el-icon-search" @click="openpmReceiptApplyRefDialog" v-if="!disableEditSubmit && !disableSave"></el-button>
                        </el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <!-- <el-form class="tl-form" ref="categoryform" :model="model" :rules="rules" label-width="150px" v-show="model.category == '2' || model.category == '3'" :disabled="disableEditSubmit || disableSave"> -->
            <el-row>
                <el-col :span="12">
                    <el-form-item label="原收据邮寄单号" prop="oldexpressno" v-show="isCancelAndReadd">
                        <el-input v-model="model.oldexpressno" :readonly="true" class="is-disabled"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="原客户名称" prop="oldcustomer" v-show="isCancelAndReadd">
                        <el-input v-model="model.oldcustomer" :readonly="true" class="is-disabled"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="原收据日期" prop="oldreceiptdate" v-show="isCancelAndReadd">
                        <el-date-picker v-model="model.oldreceiptdate" type="date" placeholder="原开票日期" value-format="yyyy-MM-dd" disabled></el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="原收据金额" prop="oldreceiptmoney" v-show="isCancelAndReadd">
                        <el-input-number v-model="model.oldreceiptmoney" controls-position="right" :step="1" :min="0" style="width:95%" :disabled="true"></el-input-number>
                        <span>元</span>
                    </el-form-item>
                </el-col>
            </el-row>
            <!-- </el-form> -->
            <el-row>
                <el-col :span="24">
                    <el-form-item label="重开原因" prop="rereceiptreason" v-show="model.category == '3'" :rules="model.category == '3' ? rules.validateRequire : { required: false }">
                        <el-input v-model="model.rereceiptreason" type="textarea" :rows="2"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label="作废原因" prop="cancelreason" v-show="model.category == '2'" :rules="model.category == '2' ? rules.validateRequire : { required: false }">
                        <el-input v-model="model.cancelreason" type="textarea" :rows="2"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <!-- <el-form class="tl-form" ref="receiptform" :model="model" :rules="rules" label-width="150px" v-show="model.category == '1' || model.category == '3'" :disabled="disableEditSubmit || disableSave"> -->
            <el-row>
                <el-col :span="24" v-show="isAddAndReadd">
                    <el-divider content-position="left"><span>【收据】相关信息</span></el-divider>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="收据开具组织" prop="receiptorgname" v-show="isAddAndReadd" :rules="isAddAndReadd ? rules.validateRequire : { required: false }">
                        <tl-ref-org v-model="model.receiptorgname" :initDisplayData.sync="model.receiptorgname" dataType="code" :singleSelect="true" @confirm="onSelectOrg" :disabled="disableEditSubmit || disableSave"></tl-ref-org>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="收据所属部门" prop="receiptdeptname" v-show="isAddAndReadd" :rules="isAddAndReadd ? rules.validateRequire : { required: false }">
                        <tl-ref-dept v-model="model.receiptdeptname" :initDisplayData.sync="model.receiptdeptname" dataType="code" nameType="fullname" :singleSelect="true" @confirm="onSelectDept" :disabled="disableEditSubmit || disableSave" :externalQueryParam="{qry_enabled:1}"></tl-ref-dept>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="收据日期类型" prop="receiptdatetype" v-show="isAddAndReadd" :rules="isAddAndReadd ? rules.validateRequire : { required: false }">
                        <el-select v-model="model.receiptdatetype" filterable clearable @change="currentReceiptDate">
                            <el-option v-for="item in codeModel.receiptdatetypeList" :key="item.code" :label="item.name" :value="item.code" />
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="收据日期" prop="receiptdate" v-show="model.receiptdatetype == '3' && (model.state == '9' || isAddAndReadd ) " :rules="model.receiptdatetype == '3' ? rules.validateRequire : { required: false }">
                        <el-date-picker v-model="model.receiptdate" type="date" placeholder="收据日期" value-format="yyyy-MM-dd"></el-date-picker>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="收据金额" prop="receiptmoney" v-show="isAddAndReadd" :rules="isAddAndReadd ? rules.validateRequire : { required: false }">
                        <el-input-number v-model="model.receiptmoney" controls-position="right" :step="1" :min="0" style="width:95%"></el-input-number>
                        <span>元</span>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="回款金额" prop="returnmoney" v-show="isAddAndReadd && model.state == '9'">
                        <el-input-number v-model="model.returnmoney" controls-position="right" :step="1" :min="0" style="width:95%" :disabled="true"></el-input-number>
                        <span>元</span>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label="收据填写要求" prop="demand" v-show="isAddAndReadd" :rules="isAddAndReadd ? rules.validateRequire : { required: false }">
                        <el-input v-model="model.demand" type="textarea" :rows="2"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label="收据说明" prop="explain" v-show="isAddAndReadd">
                        <el-input v-model="model.explain" type="textarea" :rows="2"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="客户名称" prop="customername" v-show="isAddAndReadd" :rules="isAddAndReadd ? rules.validateRequire : { required: false }">
                        <el-input v-model="model.customername" :disabled="true" class="tl-ref-selector">
                            <el-button slot="append" type="primary" icon="el-icon-search" @click="openpmCustomerRefDialog" v-if="!disableEditSubmit && !disableSave"></el-button>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="企业名称" prop="companyname" v-show="isAddAndReadd" :rules="isAddAndReadd ? rules.validateRequire : { required: false }">
                        <el-input v-model="model.companyname" :disabled="true" class="tl-ref-selector">
                            <el-button slot="append" type="primary" icon="el-icon-search" @click="openpmCustomerBillRefDialog" v-if="!disableEditSubmit && !disableSave"></el-button>
                        </el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="企业地址" prop="companyaddress" v-show="isAddAndReadd">
                        <el-input v-model="model.companyaddress" :readonly="true" class="is-disabled"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="收件人性质" prop="receivertype" v-show="isAddAndReadd" :rules="isAddAndReadd ? rules.validateRequire : { required: false }">
                        <el-select v-model="model.receivertype" filterable clearable>
                            <el-option v-for="item in codeModel.receivertypeList" :key="item.code" :label="item.name" :value="item.code" />
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="收件人" prop="receiver" v-show="isAddAndReadd" :rules="isAddAndReadd ? rules.validateRequire : { required: false }">
                        <el-input v-model="model.receiver"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="收件人电话" prop="receivertel" v-show="isAddAndReadd" :rules="isAddAndReadd ? rules.validateRequire : { required: false }">
                        <el-input v-model="model.receivertel"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label="邮寄地址" prop="mailaddress" v-show="isAddAndReadd" :rules="isAddAndReadd ? rules.validateRequire : { required: false }">
                        <el-input v-model="model.mailaddress"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label="备注" prop="description">
                        <el-input v-model="model.description" type="textarea" :rows="2"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <!-- </el-form> -->
            <el-form class="tl-form" ref="dealform" :model="model" :rules="rules" label-width="120px" v-show="model.state == '9' || model.receiptcode != null " :disabled="disableEditSubmit || disableSave">
                <el-row>
                    <el-col :span="24">
                        <el-divider content-position="left"><span>【收据邮寄】相关信息</span></el-divider>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="收据号码" prop="receiptcode">
                            <el-input v-model="model.receiptcode"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="签收单是否返回" prop="isreceiptreturn">
                            <el-select v-model="model.isreceiptreturn" filterable clearable>
                                <el-option v-for="item in codeModel.isreceiptreturnList" :key="item.code" :label="item.name" :value="item.code" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="快递单号" prop="couriernumber">
                            <el-input v-model="model.couriernumber"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="快递方式" prop="courier">
                            <el-select v-model="model.courier" filterable clearable>
                                <el-option v-for="item in codeModel.courierList" :key="item.code" :label="item.name" :value="item.code" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="实际收据日期" prop="actualreceiptdate">
                            <el-date-picker v-model="model.actualreceiptdate" type="date" placeholder="实际收据日期" value-format="yyyy-MM-dd"></el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="寄出日期" prop="maildate">
                            <el-date-picker v-model="model.maildate" type="date" placeholder="寄出日期" value-format="yyyy-MM-dd"></el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <el-collapse>
                <el-collapse-item title="【单据】相关信息">
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="申请部门" prop="deptname">
                                <tl-ref-dept v-model="model.deptcode" :initDisplayData.sync="model.deptname" :disabled="true" dataType="code" nameType="fullname" :singleSelect="true" :externalQueryParam="{qry_enabled:1}"></tl-ref-dept>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="申请公司" prop="orgname">
                                <el-input v-model="model.orgname" :readonly="true" class="is-disabled"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="申请人" prop="username">
                                <tl-ref-user v-model="model.username" :initDisplayData.sync="model.username" :disabled="true" dataType="code" :singleSelect="true"></tl-ref-user>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="申请人工号" prop="usercode">
                                <el-input v-model="model.usercode" :readonly="true" class="is-disabled"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="单据日期" prop="docdate" :rules="rules.validateRequire">
                                <el-date-picker v-model="model.docdate" type="date" placeholder="单据日期" value-format="yyyy-MM-dd"></el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="提交时间" prop="submitdate">
                                <el-date-picker v-model="model.submitdate" type="datetime" placeholder="提交时间" disabled></el-date-picker>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="审批流程" prop="flowid">
                                <el-input v-model="model.dispflowid" :readonly="true" class="is-disabled"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="状态" prop="state">
                                <el-input v-model="model.dispstate" disabled></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-collapse-item>
            </el-collapse>
        </el-form>
        <tl-approval-history ref="history" sourceType="PmReceiptApply" :sourceId="model.id" />
        <div slot="footer" class="dialog-footer">
            <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit" v-if="uiOperateState<=2">取消</el-button>
            <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="!disableEditSubmit" :disabled="disableSave">
                <svg-icon icon-class="save" />保存</el-button>
            <el-button type="primary" @click="doSubmitApproval" :loading="submitLoading" v-if="!disableEditSubmit" :disabled="disableApproval">
                <svg-icon icon-class="send" />提交审批</el-button>
            <tl-attachment sourceType="PmReceiptApply" :sourceId="model.id" :disabled="disableAttachment" :editable="stateEdit"></tl-attachment>
            <tl-attachment ref="attachmentRef" sourceType="PmReceiptApplySigned" :sourceId="model.id" btnTitle="收据签收单" :disabled="disableAttachment" :editable="true"></tl-attachment>
            <el-button type="primary" @click="$refs.history.visible = true" :disabled="disableApprovalHistory">
                <svg-icon icon-class="list" />审批历史</el-button>
            <el-button type="primary" @click="doDelApproval" :loading="delApprovalLoading" v-if="!disableEditSubmit" :disabled="disableDelApproval">
                <svg-icon icon-class="undo" />取消审批</el-button>
        </div>
        <tlpm-receipt-apply-ref ref="tlpmReceiptApplyRef" @confirm="getpmReceiptApplyRefData" :isSingleSelect="true" :externalQueryParam="{qry_projectid:model.projectid,qry_isnotcancel:'0',qry_state:'9'}"></tlpm-receipt-apply-ref>
        <tlpm-project-ref ref="pmProjectRef" @confirm="getpmProjectRefData" :isSingleSelect="true"></tlpm-project-ref>
        <tlpm-customer-ref ref="pmCustomerRef" @confirm="getpmCustomerRefData" :isSingleSelect="true"></tlpm-customer-ref>
        <tlpm-customer-bill-ref ref="pmCustomerBillRef" @confirm="getpmCustomerBillRefData" :isSingleSelect="true" :externalQueryParam="{qry_customerid:model.customerid}"></tlpm-customer-bill-ref>
    </tl-sub-page>
</template>

<script>
/** mixins */
import { mixin_approval_edit } from '@tapui/mixins/mixin_approval_edit'
/** 子组件 */
import tlpmProjectRef from '@/views/ProjectManage/pmProject/refList.vue'
import tlpmCustomerRef from '@/views/ProjectManage/pmCustomer/refList.vue'
import tlpmReceiptApplyRef from '@/views/ProjectManage/pmReceiptApply/refList.vue'
import tlpmCustomerBillRef from '@/views/ProjectManage/pmCustomerBill/refList.vue'
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
/** VUE配置 */
export default {
    mixins: [mixin_approval_edit],
    components: { tlpmProjectRef, tlpmCustomerRef, tlpmCustomerBillRef, tlpmReceiptApplyRef },
    data() {
        return {
            moduleTitle: '项目收据申请',
            urlPrefix: '/pm/receiptApply/',
            url: {
                // 额外的url
            }
        }
    },
    computed: {
        // 状态为新增或重开
        isAddAndReadd() {
            return this.model.category === '1' || this.model.category === '3'
        },
        // 状态为作废或重开
        isCancelAndReadd() {
            return this.model.category === '2' || this.model.category === '3'
        }
    },
    props: {
        projectId: {
            type: [Number, String],
            default: function() {
                return ''
            }
        },
        editFlag: {
            type: Boolean,
            default: true
        }
    },
    methods: {
        assignDefaultValue() {
            if (this.isAdd) {
                // if (this.codeModel.flowidList && this.codeModel.flowidList.length > 0) {
                //     this.$set(this.model, 'flowid', parseInt(this.codeModel.flowidList[0].id))
                // }
                // this.$set(this.model, 'orgcode', this.org.code)
                // this.$set(this.model, 'orgname', this.org.name)
                // this.$set(this.model, 'deptcode', this.dept.code)
                // this.$set(this.model, 'deptname', this.dept.fullname)
                this.$set(this.model, 'usercode', this.user.code)
                this.$set(this.model, 'username', this.user.name)
                this.$set(this.model, 'docdate', new Date())
                // 1 客户， 2 鼎信员工
                this.$set(this.model, 'receivertype', '1')
            }
        },
        // 排除各种容易造成垃圾数据的情况
        currentDatas() {
            debugger
            if (this.model.category === '2') {
                // 清除垃圾数据
                this.$set(this.model, 'receiptorgname', '')
                this.$set(this.model, 'receiptorgcode', '')
                this.$set(this.model, 'receiptdeptname', '')
                this.$set(this.model, 'receiptdeptcode', '')
                this.$set(this.model, 'receiptdatetype', '')
                this.$set(this.model, 'receiptdate', '')
                this.$set(this.model, 'receiptmoney', '')
                this.$set(this.model, 'demand', '')
                this.$set(this.model, 'explain', '')
                this.$set(this.model, 'customername', '')
                this.$set(this.model, 'companyname', '')
                this.$set(this.model, 'companyaddress', '')
                this.$set(this.model, 'receiver', '')
                this.$set(this.model, 'receivertel', '')
                this.$set(this.model, 'mailaddress', '')
                this.$set(this.model, 'receivertype', '')
                this.$set(this.model, 'customerid', '')
                this.$set(this.model, 'rereceiptreason', '')
            }
            if (this.model.category === '1') {
                // 清除垃圾数据
                this.$set(this.model, 'oldid', '')
                this.$set(this.model, 'oldreceiptcode', '')
                this.$set(this.model, 'oldexpressno', '')
                this.$set(this.model, 'oldcustomer', '')
                this.$set(this.model, 'oldreceiptdate', '')
                this.$set(this.model, 'oldreceiptmoney', '')
                this.$set(this.model, 'cancelreason', '')
                this.$set(this.model, 'rereceiptreason', '')
            }
        },
        loaded() {
            // 页面加载完毕执行
            if (!this.isAdd && this.model.docno) {
                this.title = this.title + `（单据编号：${this.model.docno}）`
            }
        },
        currentReceiptDate() {
            // this.$set(this.model, "receiptdate", '')
            // 1:开具当天 2：空着不填 3：指定日期
            if (this.model.receiptdatetype === '1') {
                this.$set(this.model, 'receiptdate', '')
            }
            if (this.model.receiptdatetype === '2') {
                this.$set(this.model, 'receiptdate', '')
            }
            // if (this.model.receiptdatetype === "3") {
            //     this.$set(this.model, "receiptdate", '')
            // }
        },
        onSelectDept(selectedDepts) {
            const selectedDept = selectedDepts[0]
            this.$set(this.model, 'receiptdeptname', selectedDept.fullname)
            this.$set(this.model, 'receiptdeptcode', selectedDept.code)
        },
        onSelectOrg(selectedOrgs) {
            const selectedOrg = selectedOrgs[0]
            this.$set(this.model, 'receiptorgname', selectedOrg.name)
            this.$set(this.model, 'receiptorgcode', selectedOrg.code)
        },
        /** 打开项目参照 */
        openpmProjectRefDialog() {
            this.$refs.pmProjectRef.visible = true
        },
        /** 获取项目参数数据 */
        getpmProjectRefData(selectionRow, selectKey, selectionValue) {
            this.$set(this.model, 'projectid', selectionRow.id)
            this.$set(this.model, 'dispprojectid', selectionRow.name)
            this.$set(this.model, 'receiptorgname', selectionRow.ownerorgname)
            this.$set(this.model, 'receiptorgcode', selectionRow.ownerorgcode)
            this.$set(this.model, 'receiptdeptname', selectionRow.ownerdeptname)
            this.$set(this.model, 'receiptdeptcode', selectionRow.ownerdeptcode)
            this.$set(this.model, 'projectcode', selectionRow.code)
            this.$set(this.model, 'projectcontractmoney', selectionRow.contractmoney)
            this.$set(this.model, 'projectmoney', selectionRow.projectmoney)
            this.$set(this.model, 'projectrecbillmoney', selectionRow.recbillmoney)
            this.$set(this.model, 'projectreceiptmoney', selectionRow.receiptmoney)
            this.$set(this.model, 'deptcode', selectionRow.ownerdeptcode)
            this.$set(this.model, 'deptname', selectionRow.ownerdeptname)
            this.$set(this.model, 'orgcode', selectionRow.ownerorgcode)
            this.$set(this.model, 'orgname', selectionRow.ownerorgname)
        },
        /** 打开项目收据参照 */
        openpmReceiptApplyRefDialog() {
            if (!this.model.projectid) {
                this.$message({
                    message: '请先选择项目！',
                    type: 'warning'
                })
                this.$refs.tlpmReceiptApplyRef.visible = false
            } else {
                this.$refs.tlpmReceiptApplyRef.visible = true
            }
        },
        /** 获取项目收据参数数据 */
        getpmReceiptApplyRefData(selectionRow, selectKey, selectionValue) {
            this.$set(this.model, 'oldid', selectionRow.id)
            this.$set(this.model, 'oldreceiptcode', selectionRow.receiptcode)
            this.$set(this.model, 'oldexpressno', selectionRow.couriernumber)
            this.$set(this.model, 'oldcustomer', selectionRow.customername)
            this.$set(this.model, 'oldreceiptdate', selectionRow.receiptdate)
            this.$set(this.model, 'oldreceiptmoney', selectionRow.receiptmoney)
        },
        /** 打开客户名称参照 */
        openpmCustomerRefDialog() {
            this.$refs.pmCustomerRef.visible = true
        },
        /** 获取客户名称参数数据 */
        getpmCustomerRefData(selectionRow, selectKey, selectionValue) {
            this.$set(this.model, 'customerid', selectionRow.id)
            this.$set(this.model, 'customername', selectionRow.name)
            this.$set(this.model, 'companyname', '')
            this.$set(this.model, 'companyaddress', '')
            this.$set(this.model, 'receiver', '')
            this.$set(this.model, 'receivertel', '')
            this.$set(this.model, 'mailaddress', '')
        },
        /** 打开开票标识参照 */
        openpmCustomerBillRefDialog() {
            if (!this.model.customerid) {
                this.$message({
                    message: '请先选择客户名称！',
                    type: 'warning'
                })
                this.$refs.pmCustomerBillRef.visible = false
            } else {
                this.$refs.pmCustomerBillRef.visible = true
            }
        },
        /** 获取开票标识参数数据 */
        getpmCustomerBillRefData(selectionRow, selectKey, selectionValue) {
            this.$set(this.model, 'companyname', selectionRow.companyname)
            this.$set(this.model, 'companyaddress', selectionRow.companyaddress)
            this.$set(this.model, 'receiver', selectionRow.receiver)
            this.$set(this.model, 'receivertel', selectionRow.receivertel)
            this.$set(this.model, 'mailaddress', selectionRow.mailaddress)
        },
        saveAttachment(resolve, reject) {
            if (this.$refs.attachmentRef.fileList.length === 0) {
                this.$tap.alert('请上传收据签收单！', 'warning')
                reject()
                return
            }
            resolve()
        },
        /** 提交前执行 */
        beforeSubmit() {
            debugger
            if (this.model.category === '2') {
                // 清除垃圾数据
                this.$set(this.model, 'receiptorgname', '')
                this.$set(this.model, 'receiptorgcode', '')
                this.$set(this.model, 'receiptdeptname', '')
                this.$set(this.model, 'receiptdeptcode', '')
                this.$set(this.model, 'receiptdatetype', '')
                this.$set(this.model, 'receiptdate', '')
                this.$set(this.model, 'receiptmoney', '')
                this.$set(this.model, 'demand', '')
                this.$set(this.model, 'explain', '')
                this.$set(this.model, 'customername', '')
                this.$set(this.model, 'companyname', '')
                this.$set(this.model, 'companyaddress', '')
                this.$set(this.model, 'receiver', '')
                this.$set(this.model, 'receivertel', '')
                this.$set(this.model, 'mailaddress', '')
                this.$set(this.model, 'receivertype', '')
                this.$set(this.model, 'customerid', '')
                this.$set(this.model, 'rereceiptreason', '')
            }
            if (this.model.category === '1') {
                // 清除垃圾数据
                this.$set(this.model, 'oldid', '')
                this.$set(this.model, 'oldreceiptcode', '')
                this.$set(this.model, 'oldexpressno', '')
                this.$set(this.model, 'oldcustomer', '')
                this.$set(this.model, 'oldreceiptdate', '')
                this.$set(this.model, 'oldreceiptmoney', '')
                this.$set(this.model, 'cancelreason', '')
                this.$set(this.model, 'rereceiptreason', '')
            }
            // 申请收据金额 合同总金额 已开票金额
            const { receiptmoney, projectcontractmoney, projectreceiptmoney } = this.model
            if (
                (receiptmoney || receiptmoney === 0) &&
                (projectcontractmoney || projectcontractmoney === 0) &&
                (projectreceiptmoney || projectreceiptmoney === 0)
            ) {
                if (receiptmoney + projectreceiptmoney > projectcontractmoney) {
                    this.$tap.alert('收据金额与项目已收据金额之和不能高于合同总金额！', 'warning')
                    return false
                }
            }
            return true
        }
    }
}
</script>

